Questions
29 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
29 / 45

How do you create a triangle or arrow shape using only CSS pseudo-elements?

Creating Triangle or Arrow Shapes with ::before and ::after in CSS

You can create triangle or arrow shapes using only CSS by leveraging pseudo-elements with borders. By setting the width and height to 0 and applying different border colors, you can make triangles pointing in various directions.

Key Points
  1. 1

    Triangles are made by setting width and height to 0 and applying border properties.

  2. 2

    The color of the visible border determines the triangle's color; other borders are set to transparent.

  3. 3

    Use ::before or ::after pseudo-elements to add arrows or triangles without extra HTML.

  4. 4

    Position the pseudo-element relative to the parent element to place the arrow as needed.

Example: Downward Arrow Using ::after

In this example, the ::after pseudo-element creates a black downward-pointing arrow below the .arrow element. The arrow is formed using CSS borders and requires no extra HTML elements.

Best Practices
  1. 1

    Use pseudo-elements for decorative arrows or pointers instead of adding extra HTML markup.

  2. 2

    Adjust border sizes and colors to control the direction and appearance of the triangle.

  3. 3

    Combine with position and transform to precisely place the arrow relative to the parent.

  4. 4

    Test across browsers to ensure the borders render correctly for different arrow directions.

Difficulty: 3/10
Topics: CSS pseudo-elements, CSS triangle technique, border-based shapes

Scenario Questions

0-2 years experience
  1. 1

    How would you create a downward-pointing arrow using only CSS pseudo-elements, and what CSS properties would you need to adjust to change its size?

  2. 2

    If you apply a background color to the element and also try to create a triangle with borders, why might the triangle not show up as expected?

2-5 years experience
  1. 1

    A tooltip arrow is misaligned on mobile — the triangle looks distorted. What could be causing this, and how would you debug it?

  2. 2

    We’re using a CSS triangle as a dropdown indicator, but it flickers on scroll in Safari. What’s likely happening, and how would you fix it without switching to SVG?

5-8 years experience
  1. 1

    We’re building a scalable icon system and considering CSS triangles for arrows instead of SVGs. What are the performance, accessibility, and maintainability tradeoffs you’d evaluate?

  2. 2

    In a design system, we need 8 different arrow directions with varying sizes and colors. How would you structure the CSS to avoid duplication and ensure consistency across themes?

8+ years experience
  1. 1

    Our legacy UI relies heavily on CSS triangles for tooltips and indicators, but we're migrating to a component library with SVG icons. What’s your strategy for phasing this out without breaking existing layouts or accessibility?

  2. 2

    Across multiple teams, we’ve seen inconsistent implementations of CSS arrows — some use borders, others use transforms or clip-path. How would you establish a cross-team standard that balances performance, maintainability, and future-proofing?

Follow-up Questions

  • What happens if you set the element's width to auto instead of 0?
  • How would you make the arrow point in a different direction without rewriting the CSS?
  • Why might this approach break in a high-contrast mode or dark theme?